﻿using MetroDataApi.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace MetroDataApi.Controllers
{
    public class OnOffStatusController : ApiController
    {

        public bool Post([FromBody]string value)
        {
            try
            {
                JObject jsonData = JObject.Parse(value);
                var prjId = jsonData["prjId"].ToObject<int>();
                var onOff = jsonData["onOff"].ToObject<int>();

                using (var db = new MetroDataDataContext())
                {
                    var prj = db.Projects.Single(p => p.PrjId == prjId);
                    prj.Status = onOff;

                    db.SubmitChanges();
                    return true;
                }
            }
            catch
            {
                return false;
            }

        }

    }
}
